<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var appStockManageDataGrid;
    $(function() {
        appStockManageDataGrid = $('#appStockManageDataGrid').datagrid({
            url : '${path }/appStockManage/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                width : '40',
                title : 'id',
                field : 'id',
                sortable : true,
                hidden : true
            }, {
                width : '150',
                title : '商品编码',
                field : 'goodsCode',
                sortable : true
            } , {
                width : '300',
                title : '名称',
                field : 'goodsName',
                sortable : true
            }, {
                width : '100',
                title : '价格',
                field : 'goodsPrice'
            } ,{
                width : '170',
                title : '当前库存',
                field : 'amount'
            } ,{
                width : '150',
                title : '创建时间',
                field : 'createTime'
            },{
                field : 'action',
                title : '操作',
                width : '100',
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/appStockManage/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="appStockManage-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAppStockManageFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.appStockManage-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            },
            toolbar : '#appStockManageToolbar'
        });
    });

    function editAppStockManageFun(id) {
        if (id == undefined) {
            var rows = appStockManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appStockManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/appStockManage/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appStockManageDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appStockManageEditForm');
                    f.submit();
                }
            } ]
        });
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="appStockManageDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
